import urllib.request

url = "http://www.baidu.com"
headers = ("User-Agent" ,"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36")
opener = urllib.request.build_opener()
opener.addheaders = [headers]
data = opener.open(url).read()
file = open("C:/Users/will.mao/Desktop/爬虫demo/TestBuildOpen.html","wb")
file.write(data)